﻿using log4net;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using PhysicalExamination5.Interface;
using PhysicalExamination5.Interface.SystemSetting;
using PhysicalExamination5.Model.SystemSetting;
using PhysicalExamination5.Service;
using PhysicalExamination5.Service.SystemSetting;
using PhysicalExamination5.WebApi.Utility.JWT;

namespace PhysicalExamination5.WebApi.Controllers.SystemSetting
{
    /// <summary>
    /// 菜单路由相关
    /// </summary>
    [ApiController]
    [ApiVersion("1.0")]
    [Route("[controller]/v{version:apiVersion}")]
    public class CaiDanRuleController : Controller
    {
        private readonly ICaiDanRule _ICaiDanRule;
        private readonly ICustomJWTService _ICustomJWTService;
        private readonly IHttpContextAccessor _httpContextAccessor;
        private static readonly ILog log = LogManager.GetLogger(typeof(IndexController));

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="ICaiDanRule"></param>
        /// <param name="ICustomJWTService"></param>
        /// <param name="httpContextAccessor"></param>
        public CaiDanRuleController(ICaiDanRule ICaiDanRule, ICustomJWTService ICustomJWTService, IHttpContextAccessor httpContextAccessor)
        {
            _ICaiDanRule = ICaiDanRule;
            _ICustomJWTService = ICustomJWTService;
            _httpContextAccessor = httpContextAccessor;

            //配置日志ip地址参数信息
            string ipAddress = _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString();
            log4net.GlobalContext.Properties["localIpAddress"] = ipAddress;
        }
        /// <summary>
        /// 查询全部菜单规则
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Authorize]
        [Route("[action]")]
        public IActionResult GetCaiDanRuleAll()
        {
            log.Debug($@"API:{System.Reflection.MethodBase.GetCurrentMethod().Name}");
            return Ok(_ICaiDanRule.GetCaiDanRuleAll());
        }
        /// <summary>
        /// 查询全部菜单目录
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Authorize]
        [Route("[action]")]
        public IActionResult GetCaiDanMuLuAll()
        {
            log.Debug($@"API:{System.Reflection.MethodBase.GetCurrentMethod().Name}");
            return Ok(_ICaiDanRule.GetCaiDanMuLuAll());
        }
        /// <summary>
        /// 新增菜单规则
        /// </summary>
        /// <param name="caiDanRule"></param>
        /// <returns></returns>
        [HttpPost]
        [Authorize]
        [Route("[action]")]
        public IActionResult PostCaiDanRuleAdd(CaiDanRuleClass caiDanRule)
        {
            log.Debug($@"API:{System.Reflection.MethodBase.GetCurrentMethod().Name}");
            return Ok(_ICaiDanRule.PostCaiDanRuleAdd(caiDanRule));
        }
        /// <summary>
        /// 修改菜单规则
        /// </summary>
        /// <param name="caiDanRule"></param>
        /// <returns></returns>
        [HttpPut]
        [Authorize]
        [Route("[action]")]
        public IActionResult PutCaiDanRuleUpdate(CaiDanRuleClass caiDanRule)
        {
            log.Debug($@"API:{System.Reflection.MethodBase.GetCurrentMethod().Name}");
            return Ok(_ICaiDanRule.PutCaiDanRuleUpdate(caiDanRule));
        }
        /// <summary>
        /// 删除菜单规则
        /// </summary>
        /// <param name="ruleId"></param>
        /// <returns></returns>
        [HttpDelete]
        [Authorize]
        [Route("[action]")]
        public IActionResult DeleteCaiDanRuleDelete(RuleId ruleId)
        {
            log.Debug($@"API:{System.Reflection.MethodBase.GetCurrentMethod().Name}");
            return Ok(_ICaiDanRule.DeleteCaiDanRuleDelete(ruleId));
        }
    }
}
